# Copyright (c) 2008-2009 Mikhail Chernov 
#
# This file is part of dcExplorer.
#
# dcExplorer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# dcExplorer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dcExplorer.  If not, see <http://www.gnu.org/licenses/>.

package dcExplorer::view::planet::Political;
use strict;

sub new 
{
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self  = {};
	$self->{Params} = shift;
	bless ($self, $class);
	return $self;
}

sub Transform
{
	my $self = shift;
	my $planet = shift;	
	my $empire = shift;
	
	my %colors = (
		0 => dcExplorer::canvas::Color->new(127, 0, 0),
		1 => dcExplorer::canvas::Color->new(0, 0, 127),
		2 => dcExplorer::canvas::Color->new(0, 127, 0),
		3 => dcExplorer::canvas::Color->new(0, 127, 0),
		4 => dcExplorer::canvas::Color->new(0, 127, 0),
		5 => dcExplorer::canvas::Color->new(0, 127, 0),
		9 => dcExplorer::canvas::Color->new(0, 127, 0)
	);
	my $jumpable = dcExplorer::canvas::Color->new(0, 255, 0);
	my $fg = undef;
	my $bg = undef;
	if (my $owner_id = $planet->getProp('owner_id'))
	{
		my $dip = ($owner_id == $empire->getProp('player_id'))?5:defined($empire->dipRelation($owner_id))?$empire->dipRelation($owner_id):9;
		$bg = $colors{$dip};
		if ($planet->getProp('jumpable'))
		{
			$fg = $jumpable;
		}
		else
		{
			$fg = $bg;
		}
	}
	else
	{
		$fg = dcExplorer::canvas::Color->new(127, 127, 127);
	}
	my $s = defined($planet->getProp('s')) ? 
		$planet->getProp('s') :
		defined($planet->getProp('img_surface')) ? 
			$planet->getProp('img_surface') * 10 + 5 : 
			50;
	my $text = undef;
	if (defined($self->{Params}->{text}) && ($self->{Params}->{text} =~ /owner/i))
	{
		my $owner_id = $planet->getProp('owner_id');
		if (defined($owner_id))
		{
			$text = $empire->players->get($owner_id)->getProp('name');
			$text = "Unknown_".$owner_id unless defined $text;
		}
	}
	return ($s, $fg, $bg, $text);
}

1;
